import { Injectable } from '@angular/core';
import { SweetAlertOptions } from 'sweetalert2';

@Injectable()
export class UtilsService {
    /**
     * Checks if input string has a valid email formay
     * @param value Value to validate
     */
    public static IsValidEmail(value: string): boolean {
        var regex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
        return value != "" && value.length > 5 && regex.test(value);
    }

    /**
     * Rounds up the input numeric value
     * @param value Input number
     */
    public static roundUp(value: number): number {
        return Math.round(value * 10) / 10;
    }

    public static getReportDate(): string{
        let now = new Date();
        return ('0' + now.getDate()).slice(-2) + ('0' + (1 + now.getMonth())).slice(-2) + now.getFullYear();
    }

    public static getBaseSwalOptions(): SweetAlertOptions {
        const swalOptions: SweetAlertOptions = {
            type: undefined,
            imageClass: 'sweetalert-icon',
            buttonsStyling: false,
            customClass: 'modal-content',
            confirmButtonClass: 'btn btn-primary',
            cancelButtonClass: 'btn btn btn-outline-dark-grey mr-3',
            reverseButtons: true,
            focusCancel: false,
            focusConfirm: false,
            showCancelButton: true
        };

        return swalOptions;
    }
}
